'''
Created on Jul 22, 2009

@author: mkiyer
'''

class GenomicInterval(object):
    """
    Describes a genomic interval
    
    Attributes:
    chrom - chromosome name of the alignment in string format 'chrN'
    chrom_start - integer location of start of alignment based on (+) strand
    chrom_end - integer location of end of alignment
    strand - strand where interval is found
    """
    def __init__(self, chrom, chrom_start, chrom_end, strand):
        self.chrom = chrom
        self.chrom_start = chrom_start
        self.chrom_end = chrom_end
        self.strand = strand

    def __str__( self ):
        return '\t'.join([self.chrom, str(self.chrom_start), 
                          str(self.chrom_end), self.strand])

    def __repr__(self):
        return self.__class__.__name__ + \
            "('%s', '%s', '%s', '%s')" % \
            (self.chrom, self.chrom_start, self.chrom_end, self.strand)

class Alignment(GenomicInterval):
    '''Describes the location of a sequence alignment
    
    Attributes:
    chrom - chromosome name of the alignment in string format 'chrN'
    chrom_start - integer location of start of alignment based on (+) strand
    chrom_end - integer location of end of alignment
    num_mismatches - number of alignment mismatches
    '''
    def __init__(self, chrom, chrom_start, chrom_end, strand, seq=None, mismatches=None):
        super(Alignment, self).__init__()
        self.chrom = chrom
        self.chrom_start= chrom_start
        self.chrom_end = chrom_end
        self.strand = strand
        self.seq = seq
        self.mismatches = mismatches
    
    def __repr__(self):
        return self.__class__.__name__ + \
            "('%s', '%s', '%s', '%s', '%s', '%s')" % \
            (self.chrom, self.chrom_start, self.chrom_end, self.strand,
             self.seq, self.mismatches) 
    
    def maps_to_genome(self):
        return self.chrom.startswith('chr')
    def maps_to_genes(self):
        return self.chrom.startswith('ucsc')

def maps_to_genome(chrom):
    return chrom.startswith('chr')

def maps_to_genes(chrom):
    return chrom.startswith('ucsc')